using System;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Globalization;

namespace Camalon.Drawing
{
    /// <summary>
    /// Using the Intensity you can specify intensity of color on a particular position. The 
    /// ColorIntensity structure provides two properties Position and Intensity, measured in percent. 
    /// The Position property represents a proportion of the distance along the gradient line 
    /// and the Intensity property represents the proportion of the starting and ending colors 
    /// in the gradient at the Position along the gradient line.
    /// </summary>
	[Serializable]
	[TypeConverter(typeof(ColorIntensityConverter))]
	public struct ColorIntensity
	{
		private float	_intensity;
		private float	_position;

        /// <summary>
        /// Initializes a new instance of the <see cref="ColorIntensity"/> struct.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="intensity">The intensity.</param>
		public ColorIntensity( float position, float intensity )
		{
			_intensity				= intensity;
			_position				= position;
		}



        /// <summary>
        /// Initializes a new instance of the <see cref="ColorIntensity"/> struct.
        /// </summary>
        /// <param name="colorIntensity">The color intensity that initializes this instance.</param>
		public ColorIntensity( ColorIntensity colorIntensity )
		{
			_intensity				= colorIntensity._intensity;
			_position				= colorIntensity._position;

		}

		#region operatoren
		public override bool Equals(object obj)
		{
			if(!( obj is ColorIntensity)) return false;

			return Equals((ColorIntensity)obj);
		}

		public bool Equals(ColorIntensity value)
		{
			return _intensity == value._intensity && _position == value._position;
		}

		public override int GetHashCode()
		{
			return _intensity.GetHashCode()^_position.GetHashCode();
		}

		public static bool operator ==(	ColorIntensity value1,ColorIntensity value2	)
		{
			return value1._intensity == value2._intensity && value1._position == value2._position;
		}

		public static bool operator !=(	ColorIntensity value1,ColorIntensity value2	)
		{
			return !(value1== value2);
		}
		#endregion operatoren


        /// <summary>
        /// Gets an empty color intensity object.
        /// </summary>
        /// <value>The empty.</value>
		public static ColorIntensity Empty
		{
			get{ return new ColorIntensity(0.0f,0.0f);}
		}

        /// <summary>
        /// Gets a value indicating whether this instance is empty.
        /// </summary>
        /// <value><c>true</c> if this instance is empty; otherwise, <c>false</c>.</value>
		[Browsable(false)]
		public bool IsEmpty
		{
			get{ return _intensity == 0.0f && _position == 0.0f;}
		}


        /// <summary>
        /// Gets the identity value.
        /// </summary>
        /// <value>The identity.</value>
		public static ColorIntensity Identity
		{
			get{ return new ColorIntensity(1.0f,1.0f);}
		}

        /// <summary>
        /// Gets a value indicating whether this instance is identity.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is identity; otherwise, <c>false</c>.
        /// </value>
		[Browsable(false)]
		public bool IsIdentity
		{
			get{ return _intensity == 1.0f && _position == 1.0f;}
		}



        /// <summary>
        /// Gets or sets the intensity that represents the proportion of the starting and ending colors 
        /// in the gradient at the Position along the gradient line.
        /// </summary>
        /// <value>The intensity.</value>
		[DefaultValue( 1.0f )]
		[TypeConverter(typeof(PercentConverter))]
		[RefreshProperties( RefreshProperties.All)]
		public float Intensity
		{
			get{ return _intensity;  }
			set
			{ 
				if( value < 0f) value = 0f;
				if( value > 1f) value = 1f;
				_intensity = value;
			}
		}


        /// <summary>
        /// Gets or sets the position that represents a proportion of the distance along the gradient line.
        /// </summary>
        /// <value>The position.</value>
		[DefaultValue( 0.0f )]
		[TypeConverter(typeof(PercentConverter))]
		[RefreshProperties( RefreshProperties.All)]
		public float Position
		{
			get{ return _position;  }
			set
			{ 
				if( value < 0f) value = 0f;
				if( value > 1f) value = 1f;
				_position = value;
			}
		}



	}




}
